package com.okami.spring.aop;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * @author: TanJingyu
 * @create: 2021-03-28 15:33
 **/
//@Configuration(proxyBeanMethods = false)
public class AopConfiguration {

    @Configuration(proxyBeanMethods = false)
    @EnableAspectJAutoProxy(proxyTargetClass = false)
    @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false",
            matchIfMissing = false)
    static class JdkDynamicAutoProxyConfiguration {

        @Bean("aopDemo")
        public Demo demo() {
            return new Demo();
        }

    }

    @Configuration(proxyBeanMethods = false)
    @EnableAspectJAutoProxy(proxyTargetClass = true)
    @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true",
            matchIfMissing = true)
    static class CglibAutoProxyConfiguration {

        @Bean("aopDemo")
        public Demo demo() {
            return new Demo();
        }
    }
}
